package com.apes.fico.masterdata.gl.respository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.fico.masterdata.gl.model.AccountingChartDistributionCompany;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface AccountingChartDistributionCompanyRepository extends CustomRepository<AccountingChartDistributionCompany, String> {
    List<AccountingChartDistributionCompany> findAllByAccSystem_Id(String Id);

    List<AccountingChartDistributionCompany> findAllByAccSystem_IdAndCompany_Id(@Param("accSystem_id") String accSystem_id, @Param("company_id") String company_id);

    AccountingChartDistributionCompany findByCompany_Id(String company);

    @Query(
            value = "select new map(f.id as id, f.party.name as name) from AccountingChartDistributionCompany t left join t.company f",
            countQuery = "select count(*) from AccountingChartDistributionCompany where 1 = 1"
    )
    Page<Map<String, Object>> findAllParty(Pageable pageable);

    @Query("select new map(T.accSystem.accIdRule as accIdRule ) from AccountingChartDistributionCompany T where  T.company.id=:company")
    Map<String, Object> findByCompany(@Param("company") String company);
}
